package algorithm;

public class leetcode_0061 {
    public ListNode rotateRight(ListNode head, int k) {
        if(head==null) return head;
        ListNode p=head;
        ListNode q=p;
        int num=1;
        while(p.next!=null){
            p=p.next;
            num++;
        }
        k=k%num;
        p=head;
        for(int i=0;i<k;++i){
            p=p.next;
        }
        while(p.next!=null){
            p=p.next;
            q=q.next;
        }
        p.next=head;
        p=q.next;
        q.next=null;
        return p;
    }
}
